<div class="mainBox">
	<div class="row">
		<div class="col-lg-12">
			<h2 class="page-header"><?php echo $title_for_layout?></h2>
		</div>
	</div>
	<div class="searchBox">
		<?php
		echo $this->Form->create('News');
		echo $this->Form->input('name', array(
			'label' => 'Tiêu đề',
			'class' => 'form-control w200',
			'div' => false,
		));

		echo $this->Form->submit('Search',array(
				'class' => 'btn btn-primary',
				'id' => 'ProductFilter',
				'title' => 'Search',
				'label' => false,
				'div' => false
			));

		echo $this->Form->end();
		?>
	</div><!-- /.search -->
</div><!-- /.mainBox -->

<div id="mainTable">
	<div class="row">
		<div class="col-sm-6">
			<?php
			$start = ($this->Paginator->current($model = null) - 1) * $page_number_limit + 1;
			$end = $start + sizeof($datas) - 1;
			?>
			<div class="dataTables_info" id="dataTables-example_info" >Showing <?php echo $start;?> to <?php echo $end;?> of <?php echo $this->Paginator->param('count');?> entries</div>
		</div>
		<div class="col-sm-6">
			<div id="dataTables-example_paginate" class="dataTables_paginate paging_simple_numbers">
				<ul class="pagination flRight box25">
				<?php
				if($this->Paginator->param('count') > $page_number_limit):
					echo $this->Paginator->prev(__('Previous'), array(
						'class' => 'previous',
						'tag' => 'li',
						'disabledTag' => 'a'
					));

					echo $this->Paginator->numbers(array(
						'separator' => '    ',
						'tag' => 'li',
						'currentClass' => 'active',
						'currentTag' => 'a'
					));

					echo $this->Paginator->next(__('Next'), array(
						'class' => 'next',
						'tag' => 'li',
						'disabledTag' =>'a'
					));
				endif;
				?>
				</ul><!-- /.pagination -->
			</div>
		</div>
	</div>
	<table class="table table-striped table-bordered table-hover" id="dataTables-example">
		<thead>
			<tr>
				<th style="text-align:center">STT</th>
				<th>Ảnh</th>
				<th>Tiêu đề</th>
				<th>Danh mục</th>
				<th>Tin HOT</th>
				<th>Hoạt động</th>
				<th>Lượt xem</th>
				<th style="text-align:center"><img alt="sửa" src="<?php echo $this->webroot ?>img/edit.png" class="image"></th>
				<th style="text-align:center"><img alt="Xóa" src="<?php echo $this->webroot ?>img/delete.gif" class="image"></th>
			</tr>
		</thead>
		<tbody>
			<?php if ($this->Paginator->param('count') > 0) :?>
				<?php
				$countno = ($this->Paginator->current($model = null) - 1) * $page_number_limit;
				foreach ($datas as $news):
					$countno++;
				?>
				<tr <?php echo $changeBgTr; ?>>
					<td align="center"><?php echo $countno;?></td>
					<td><?php echo $this->Html->image('/uploads/'. $news['News']['new_picture'], array('alt' => '', 'fullBase' => false, 'height' => '120'));?></td>
					<td>
						<?php
						$link = $this->Html->url(
								array(
										'controller' => 'news',
										'action' => 'detail',
										'full_base' => false,
										'news_id' => $news['News']['id'],
										'news_rewrite' => $news['News']['new_rewrite'],
										'cat_rewrite' => $news['Categories']['cat_rewrite'],
										'ext' => 'html',
								)
						);
						$link = preg_replace('#/admin/#', '/', $link);
						?>
						<a style="text-decoration:none" href="<?php echo $link;?>" target="_blank"><?php echo $news['News']["name"];?></a>
					</td>
					<td>
						<?php
						foreach ($listCategory as $category){
							if ($category['id'] == $news['News']['category_id']){
								echo $category['cat_name'];
							}
						}
						?>
					</td>
					<td align="center">
						<?php
							$checked = 0;
							if ($news['News']['new_hot'] == 1) {
								$checked = 1;
							}
						?>
						<a class="news_update_active"  href="<?php echo $this->Html->url(array('controller' => 'news', 'action' => 'update', $news['News']['id'], 'new_hot')) ?>" title="Active or Inactive" rel="tooltip">
							<?php echo $this->Html->image("check_$checked.gif", array("alt" => "", 'class' => 'image_hot', 'value' => abs($news['News']['new_hot'] - 1)));?>
						</a>
					</td>
					<td align="center">
						<?php
							$checked = 0;
							if ($news['News']['active'] == 1) {
								$checked = 1;
							}
						?>
						<a class="news_update_active"  href="<?php echo $this->Html->url(array('controller' => 'news', 'action' => 'update', $news['News']['id'], 'active')) ?>" title="Active or Inactive" rel="tooltip">
							<?php echo $this->Html->image("check_$checked.gif", array("alt" => "", 'class' => 'image_hot', 'value' => abs($news['News']['active'] - 1)));?>
						</a>
					</td>
					<td align="center"><?php echo $news['News']['new_hits'];?></td>
					<td align="center">
						<a href="<?php echo $this->Html->url(array('controller' => 'news', 'action' => 'edit', $news['News']['id'])) ?>">
							<?php echo $this->Html->image("edit.png", array("alt" => "sửa", 'class' => 'image'));?>
						</a>
					</td>
					<td align="center">
					<?php
						echo $this->Form->postLink(
							'Delete',
							array('controller' => 'news', 'action' => 'delete', $news['News']['id']), null, __('Are you sure you want to delete ?', $news['News']['id'])
						);
					?>
					</td>

				</tr>
				<?php endforeach;//end foreach $datas?>
			<?php endif;//end if count($datas)?>
		</tbody>
	</table>
	<div class="row">
		<div class="col-sm-6">
			<div class="dataTables_info" id="dataTables-example_info" >Showing <?php echo $start;?> to <?php echo $end;?> of <?php echo $this->Paginator->param('count');?> entries</div>
		</div>
		<div class="col-sm-6">
			<div id="dataTables-example_paginate" class="dataTables_paginate paging_simple_numbers">
				<ul class="pagination flRight box25">
				<?php
				if($this->Paginator->param('count') > $page_number_limit):
					echo $this->Paginator->prev(__('Previous'), array(
						'class' => 'previous',
						'tag' => 'li',
						'disabledTag' => 'a'
					));

					echo $this->Paginator->numbers(array(
						'separator' => '    ',
						'tag' => 'li',
						'currentClass' => 'active',
						'currentTag' => 'a'
					));

					echo $this->Paginator->next(__('Next'), array(
						'class' => 'next',
						'tag' => 'li',
						'disabledTag' =>'a'
					));
				endif;
				?>
				</ul><!-- /.pagination -->
			</div>
		</div>
	</div>


</div>
<script type="text/javascript">
function checkAll(){

	if ($('#check-all').attr('checked') == true) {
		$('.item-element').attr('checked', true);
	} else {
		$('.item-element').attr('checked', false);
	}
}
</script>

<?php echo $this->element('sql_dump'); ?>